﻿using System;
using System.Collections.Generic;
using GestureMatching.Algorithm;
using GestureMatching.DataStructure;

namespace GestureMatching
{
    public class Matcher
    {
        private LinkedList<Dictionary<String, Object>> allGestureRecord;
        private SimilarityCalculator similarityCalculator = new SimilarityCalculator();

        public Matcher(LinkedList<Dictionary<String, Object>> allGestureRecord)
        {
            this.allGestureRecord = allGestureRecord;
        }

        public LinkedList<Dictionary<String, Object>> GetAllGestureRecord()
        {
            return allGestureRecord;
        }

        public Dictionary<String, Object> Matching(TimingQueue firstGesture)
        {
            Dictionary<String, Object> matchedGestureRecord = null;
            double bestSimilarity = 0;

            foreach (Dictionary<String, Object> gestureRecord in allGestureRecord)
            {
                TimingQueue secondGesture = (TimingQueue)gestureRecord[GestureRecordManager.KEY_GESTURE];
                double similarity = similarityCalculator.CalculateSimilarity(firstGesture, secondGesture);

                if (similarity > bestSimilarity)
                {
                    bestSimilarity = similarity;
                    matchedGestureRecord = gestureRecord;
                }
            }

            return matchedGestureRecord;
        }
    }
}